/**
 * <p>Copyright: Copyright (c) 2014</p>
 * <p>Company: ---Technology Co. Ltd</p>
 * <p>2014-4-30</p>
 * @author Jan.Zhang
 */
package com.xianl.busiplat.util;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;


/** 
 * desc:
 * <p>author: Jan.Zhang </p>
 * date: 2014-4-30
 */
public class ClassUtil {

	/**
	 * desc:
	 * <p>author: Jan.Zhang </p>
	 *  date : 2014-4-30 
	 * @param clazz
	 * @param index
	 * @return
	 */
	public static Class<?> getSuperClassGenricType(Class<?> clazz, int index) {
		
		Type genType = clazz.getGenericSuperclass();
		if(!(genType instanceof ParameterizedType) ) {
			return Object.class;
		}
		Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
		if(index >= params.length || index < 0 ) {
			return Object.class;
		}
		if(!(params[index] instanceof Class) ) {
			return Object.class;
		}
		return (Class<?>) params[index];
	}

	/**
	 * desc:
	 * <p>author: Jan.Zhang </p>
	 *  date : 2014-4-30 
	 * @param clazz
	 * @return
	 */
	public static String getClassName(Class<?> clazz) {
		return getSuperClassGenricType(clazz, 0).getSimpleName();
	}
}
